<template>
  <div class="_wz_cent_main _wz_certificateCriterion">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="运输企业" v-if="!seeCarData">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem label="达标等级">
          <i-select v-model="formDataSearch.certificateLevel" filterable placeholder="请选择达标等级" clearable>
            <Option value="1">一级</Option>
            <Option value="2">二级</Option>
            <Option value="3">三级</Option>
          </i-select>
        </FormItem>
        <FormItem label="证书状态" v-if="searchType">
          <i-select v-model.number="formDataSearch.certificateState" filterable placeholder="请选择证书状态" clearable>
            <Option :value="1">已生效</Option>
            <Option :value="2">已逾期</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <p slot="extra">
        <Button type="primary" @click="addTableData" v-if="!seeCarData">添加</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>

    <!--添加修改-->
    <Drawer :title="formTitle" v-model="formOperation" width="900" :mask-closable="false" :draggable="true" :styles="formOperationStyles">
      <certificateCriterionForm v-if="formOperation" @closeFun="closeFun" :selectData="selectData"></certificateCriterionForm>
    </Drawer>
    <!--查看-->
    <Drawer title="查看" v-model="formOperation1" width="900" :mask-closable="false" :draggable="true">
      <certificateCriterionFormSee v-if="formOperation1" :selectData="selectData"></certificateCriterionFormSee>
    </Drawer>

    <Spin size="large" fix v-if="spinShow"></Spin>

  </div>
</template>
<script>
// import certificateData from './certificateData.vue'
import certificateCriterionForm from './certificateCriterionForm.vue'
import certificateCriterionFormSee from './certificateCriterionFormSee.vue'
import wzTbale from "../../../components/table/table";

export default {
  props: ['seeCarData'],//接收来自父组件的数据
  components: {
    // certificateData,//详情
    certificateCriterionForm,//详情
    wzTbale,//列表
    certificateCriterionFormSee
  },
  data() {
    return {
      subDeptList: [],//运输企业
      spinShow: false,//本页加载
      searchType: false,//搜索条件
      formTitle: '',
      formOperation: false,
      formOperation1:false,
      uuid: '',
      seeMoreType: false,
      modal1: false,//离职理由
      reason: '同意',//离职理由理由
      personType: [],//从业类型
      formDataSearch: {
        deptUuid:!!this.seeCarData?this.seeCarData.deptUuid:''
      },//搜索表单数据
      dataListHeight: "400px",//中间数据高度

      selectData: null,//点选数据
      reasonType: "",//审核类型
      jobState: 0,//解聘使用
      formOperationStyles: {//表单左侧移出css
        height: 'calc(100% - 55px)',
        overflow: 'auto',
        paddingBottom: '53px',
        position: 'static'
      },


      tableData: {
        url: this.apiUrl.webApi + "/safety/certificate/certificateCriterionPageList",//请求地址
        method: 'post',//请求方式
        where: {deptUuid:!!this.seeCarData?this.seeCarData.deptUuid:''},//搜索条件
        height: 'auto',//表格高度 auto
        page: true,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {title: '证书编号', minWidth: 160, key: 'certificateNo'},
          {title: '达标等级', minWidth: 100, key: 'certificateLevel', render: (h, params) => {
              if (params.row.certificateLevel == 1) {
                return h('span','一级');
              }else if (params.row.certificateLevel == 2){
                return h('span', '二级');
              }else if (params.row.certificateLevel == 3){
                return h('span','三级');
              }
            }
          },
          {title: '评定机构', minWidth: 200, key: 'certificateIssueName'},
          {title: '证书类别', minWidth: 200, key: 'certificateType'},
          {title: '经营类型', minWidth: 120, key: 'certificateMold'},
          {title: '发证日期', minWidth: 120, key: 'certificateReleaseDate', render: (h, params) => {
              return h('span',!!params.row.certificateReleaseDate?params.row.certificateReleaseDate:'--');
            }
          },
          {title: '截至日期', minWidth: 120, key: 'certificateDueDate', render: (h, params) => {
              return h('span',!!params.row.certificateDueDate?params.row.certificateDueDate:'--');
            }
          },
          {title: '运输企业', minWidth: 260, key: 'deptName'},
          {title: '证书状态', minWidth: 140,fixed: 'right', render: (h, params) => {
              if (params.row.certificateState == 1) {
                return h('Tag', {props: {type: 'dot',color: 'success'}}, '已生效');
              }else if (params.row.certificateState == 2){
                return h('Tag', {props: {type: 'dot',color: 'error'}}, '已逾期');
              }else{
                return h('Tag', {props: {type: 'dot',color: '#ff7600'}}, '办理中');
              }
            }
          },
          {
            title: '操作', fixed: 'right', width:120,
            render: (h, params) => {
              var operationButtons = [];

              operationButtons.push(
                h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.selectData = JSON.parse(JSON.stringify(params.row))
                      this.formOperation1 = true;
                    }
                  }
                }, "查看")
              )

              var buttonList = [];

              //修改
              buttonList.push(h('DropdownItem', {
                nativeOn: {
                  click: () => {
                    let that = this;
                    that.formTitle = "修改";
                    that.selectData = JSON.parse(JSON.stringify(params.row))
                    that.formOperation = true;
                  }
                }
              }, '修改'))
              //删除
              buttonList.push(h('DropdownItem', {
                nativeOn: {
                  click: () => {
                    let that = this;
                    that.$Modal.confirm({
                      title: '删除提醒',
                      content: '确定要删除选中的记录？',
                      onOk: () => {
                        that.axios.post(that.apiUrl.webApi + "/safety/certificate/certificateCriterionDelete", {"uuid": params.row.uuid}).then(res => {
                          if (!!res) {
                            that.$Message.success('数据删除成功.')
                            that.searchSubmit()
                          }

                        }).catch(err => {
                          console.log("失败", err)
                        })
                      },
                      onCancel: () => {
                        //点击取消
                      }
                    })
                  }
                }
              }, '删除'))
              if (buttonList.length > 0 && !this.seeCarData) {
                if(operationButtons.length > 0){
                  operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                }
                operationButtons.push(h('Dropdown', {props: {trigger: "hover", transfer: true}},
                  [
                    h('span', {style: {"color": "#2d8cf0", "cursor": "pointer"}}, '更多▼'),
                    h('DropdownMenu', {slot: "list"}, buttonList)
                  ])
                )
              }
              return operationButtons;
            }
          },
        ],
        format: {//返回数据格式
          list: ['data'],//数据list
          count: ['count'],//数据总量
        },
      },
    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态
  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态
    let that = this;
    //运输企业
    that.axios.post(that.apiUrl.coreDeptCoreDeptList, {}).then(res => {
      if (!!res) {
        that.subDeptList = res.data.data;
      }
    }).catch(err => {
      console.log("失败", err)
    });
  },
  methods: {//执行的方法
    searchSubmit() {//搜索
      this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
      this.$refs.wzTbale.tableLoadData(true);
    },
    //人员添加
    addTableData() {
      let that = this;
      that.formTitle = "添加";
      that.selectData = {};
      that.formOperation = true;
    },

    //添加修改触发后关闭刷新
    closeFun(data) {
      let that = this;
      if (data) {//添加修改 刷新表单
        that.searchSubmit();
      }
      that.formOperation = false;
    },
  },
  watch: {//监听

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_certificateCriterion {
  height: 100%;
  display: flex;
  flex-direction: column;
}
</style>
